-- Keymaps are automatically loaded on the VeryLazy event
-- Default keymaps that are always set: https://github.com/LazyVim/LazyVim/blob/main/lua/lazyvim/config/keymaps.lua
-- Add any additional keymaps here

-- tips:
-- 使用:s 进行文本替换
-- :{作用范围}s/{目标}/{替换}/{替换标志}
-- 例如：:s/keymap/key/g      .s搜索当前行 2,10s搜索2-10行 %s搜索全文   g表示把匹配到的所有keymap替换成key, c 是手动替换

-- <C-v> or <lerder>v 进入 visual block 模式, 选中要插入几行文字，按下I (大写i) 进行编辑，<esc>退出即可进行多行操作
-- g 回到上一步 例gi 回到上一次插入的地方
-- vi'  选中‘’内文本 同理di( 删除（）内文本, ci[{ 把[]改成{} ya[ 把[]内包括[]复制
-- q录制宏 qa录制名叫a的宏，@a播放宏

-- %快速跳到上一个/下一个括号，*匹配单前单词

-- gsaw“ 快速为当前当前单词添加”“

local keymap = vim.keymap


keymap.set('i', 'jk', '<esc>', { desc = "退出插入模式" })
keymap.set('i', '<C-z>', '<esc>ui', { desc = "撤销" })
keymap.set('i', '<C-y>', '<esc><C-r>i', { desc = "取消撤销" })
keymap.set('n', '<C-y>', '<esc><C-r>', { desc = "取消撤销" })
keymap.set('n', '<C-c>', 'yy', { desc = "copy" })
keymap.set('n', '<leader>v', '<C-v>', { desc = "V-block" })
keymap.set('n', 'op', 'o<esc>p', { desc = "到下一行粘贴" })
keymap.set({ 'i', 'n' }, '<leader>d', '<esc>yyp', { desc = "复制到下一行" })
keymap.set({ 'i', 'n' }, '<C-a>', '<esc>ggVG', { desc = "全选" })
keymap.set({ 'v', 'n' }, '9', '0', { desc = "行头" })
keymap.set({ 'v', 'n' }, '0', '^', { desc = "行头(无空格)" })
keymap.set({ 'v', 'n' }, '-', '$', { desc = "行尾" })
keymap.set({ 'v', 'n' }, '<leader>t', '<esc>bve', { desc = "选中光标所在单词" })
keymap.set('n', '==', 'ggVG=<esc>', { desc = '代码对齐' })
keymap.set('v', '<tab>', '>gv', { desc = "缩进" })
keymap.set('v', '<S-tab>', '<gv', { desc = "缩出" })

-- Ctrl 跳转窗口
keymap.set("n", "<C-Left>", "<C-w>h", { desc = "跳转到左窗口" })
keymap.set("n", "<C-Down>", "<C-w>j", { desc = "跳转到下窗口" })
keymap.set("n", "<C-Up>", "<C-w>k", { desc = "跳转到上窗口" })
keymap.set("n", "<C-Right>", "<C-w>l", { desc = "跳转到右窗口" })

keymap.set("n", "<C-h>", "<C-w>h", { desc = "跳转到左窗口" })
keymap.set("n", "<C-j>", "<C-w>j", { desc = "跳转到下窗口" })
keymap.set("n", "<C-k>", "<C-w>k", { desc = "跳转到上窗口" })
keymap.set("n", "<C-l>", "<C-w>l", { desc = "跳转到右窗口" })

-- Shift 上下左右控制窗口大小
keymap.set("n", "<S-Down>", "<cmd>resize +2<cr>", { desc = "Increase Window Height" })
keymap.set("n", "<S-Up>", "<cmd>resize -2<cr>", { desc = "Decrease Window Height" })
keymap.set("n", "<S-Left>", "<cmd>vertical resize -2<cr>", { desc = "Decrease Window Width" })
keymap.set("n", "<S-Right>", "<cmd>vertical resize +2<cr>", { desc = "Increase Window Width" })

keymap.set("n", "<S-j>", "<cmd>resize +2<cr>", { desc = "Increase Window Height" })
keymap.set("n", "<S-k>", "<cmd>resize -2<cr>", { desc = "Decrease Window Height" })
keymap.set("n", "<S-l>", "<cmd>vertical resize -2<cr>", { desc = "Decrease Window Width" })
keymap.set("n", "<S-h>", "<cmd>vertical resize +2<cr>", { desc = "Increase Window Width" })

-- buffer
-- "<A-left>" 与wezterm 冲突
keymap.set("n", "<A-left>", "<cmd>BufferLineCyclePrev<cr>", { desc = "Prev Buffer" })
keymap.set("n", "<A-right>", "<cmd>BufferLineCycleNext<cr>", { desc = "Next Buffer" })
keymap.set("n", "<A-h>", "<cmd>bprevious<cr>", { desc = "Prev Buffer" })
keymap.set("n", "<A-l>", "<cmd>bnext<cr>", { desc = "Next Buffer" })

keymap.set("n", "<tab>", "<cmd>BufferLineCyclePrev<cr>", { desc = "Prev Buffer" })
keymap.set("n", "<S-tab>", "<cmd>BufferLineCycleNext<cr>", { desc = "Next Buffer" })


-- 快速注释
keymap.set("v", "<A-/>", "<cmd>normal gc<cr>", { desc = "注释此段" })
keymap.set("n", "<A-/>", "<cmd>normal gcc<cr>", { desc = "注释此行" })

-- 摸鱼, 假装升级系统
keymap.set('n', '<F12>', ':!start C:\\"Program Files (x86)"\\Microsoft\\Edge\\Application\\msedge.exe --kiosk https://tools.devhjz.com/fakeupdate/win10u/index.html --edge-kiosk-type=fullscreen <cr>', { desc = "摸鱼" })
